package zeebe.demo;

import io.zeebe.client.ZeebeClient;
import io.zeebe.client.api.response.ActivatedJob;
import io.zeebe.client.api.worker.JobClient;
import io.zeebe.client.api.worker.JobHandler;

import java.util.HashMap;
import java.util.Map;

public class WorldJobWorkerHandler implements JobHandler {
    ZeebeClient zeebeClient;

    public WorldJobWorkerHandler(ZeebeClient client) {
        this.zeebeClient = client;
    }

    @Override
    public void handle(JobClient jobClient, ActivatedJob activatedJob) throws Exception {
        System.out.println("开始执行worldJobWorker");
        String value = String.valueOf(activatedJob.getVariablesAsMap().get("hellooutput"));
        String result = value + " , this is a beautifule world";
        System.out.println(result);

        Map<String, Object> map = new HashMap<>();
        map.put("result", result);
        jobClient.newCompleteCommand(activatedJob.getKey())
                .variables(map)
                .send()
                .join();
    }
}
